"""
urlencode方法
"""


import urllib.parse
import urllib.request

# url = "https://www.baidu.com/s?wd=周杰伦&sex=男"

data = {"wd": "周杰伦", "sex": "男"}

a = urllib.parse.urlencode(data)
print(a)

base_url = "https://www.baidu.com/s?"

url = base_url + a

print(url)

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50"
}

request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read()
print(content.decode("utf-8"))
